package com.company.bookstore.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.bookstore.entities.book_module.BookCategory;
import com.company.bookstore.entities.book_module.Category;
import com.company.bookstore.mapper.book_module.CategoryMapper;
import com.company.bookstore.service.book_module.CategoryService;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 姬深威
 * @since 2020-09-12
 */
@Service
@Transactional
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Resource
    CategoryMapper categoryMapper;

    @Override
    public List<Category> getAllCategories() {
        List<Category> categories = categoryMapper.getAllCategories();
        return categories;
    }

    @Override
    public Category getCategoryById(Integer id) {
        return categoryMapper.getCategoryById(id);
    }

    @Override
    public Integer addCategory(Category category) {
        categoryMapper.addCategory(category);
        Integer categoryId = category.getId();
        return categoryId;
    }

    @Override
    public Integer updateCategory(Category category) {
        Integer affectRow = categoryMapper.updateCategory(category);
        return affectRow;
    }

    @Override
    public Integer deleteCategory(Integer cId) {
        Integer affectRow = categoryMapper.deleteCategory(cId);
        return affectRow;
    }


}
